<?php

    //----- SESSION

    require 'root/config.php'; // CONFIG


    // REQUIRES/INCLUDES
    require_once('class/link.php');
    //require_once('model/databaseio.php');
    //require_once('model/urlio.php');
    //require_once('model/sessionio.php');

    $dir = isset($_GET['dir']) ? $_GET['dir'] : 'home';
    $sub = isset($_GET['sub']) ? $_GET['sub'] : false;
    $act = isset($_GET['act']) ? $_GET['act'] : false;
    $msg = isset($_GET['msg']) ? $_GET['msg'] : false;
	
    $page = 'app/' . $dir . '/controller/' . (($sub) ? $sub : $dir) . '.php';

    // gateway(); // GATEWAY

    include $page; // controller call

    $scriptFile = 'app/' . $dir . '/script.php';
    $styleFile = 'app/' . $dir . '/style.php';
    if (file_exists($styleFile)) {include $styleFile;}
    if (file_exists($scriptFile)) {include $scriptFile;}
	
?>
<!DOCTYPE html>
<html>
    <head>
	<meta charset="UTF-8">
	<link rel="stylesheet" href="css/default.css" >
	<?php
	    // <link rel="stylesheet" href="css/nav.css" >
	    if (isset($styles)) {
		foreach ($styles as $style) {
		    echo '<link rel="stylesheet" href="css/' . $style . '.css" >';
		}
	    }
	?>
	<style></style>
	<?php
	    // <script src="js/FILENAME.js"></script>
	    if (isset($scripts)) {
		foreach ($scripts as $sript) {
		    echo '<script src="js/' . $script . '.js" >';
		}
	    }
	?>
	<script></script>
    </head>
    <body>
	<div id="page">
	    <header>
		<h1><?php echo APP_TITLE; ?></h1>
		<h2>Nav</h2>
		<?php include 'root/nav.php'; ?>
	    </header>
	    <div id="body">
		<?php
		    if (file_exists('app/' . $dir . '/menu.php')) {
			echo '<h2>Sub-Nav</h2>';
			include 'root/subNav.php';
		    }
		?>
		<div id="content">
		    <?php if(file_exists('app/' . $page)) {include 'app/' . $page;} // view call ?>
		</div>
	    </div>
	    <!--<footer></footer>-->
	</div>
    </body>
</html>
